package org.wedding.center.util;
import java.io.File;
import java.io.IOException;

public class FileAndFolderCreator {

    public static void createFilesInFolders(String basePath, String[] fileNames) {
        for (String fileName : fileNames) {
            // 创建以文件名命名的文件夹
            String folderPath = basePath + File.separator + fileName;
            File folder = new File(folderPath);
            if (!folder.exists()) {
                if (folder.mkdir()) {
                    System.out.println("创建文件夹: " + folderPath);
                } else {
                    System.out.println("创建文件夹失败: " + folderPath);
                    continue;
                }
            }

            // 在以文件名命名的文件夹内创建.vue和*Layer.vue文件
            String[] vueSuffixes = {".vue", "Layer.vue"};
            for (String suffix : vueSuffixes) {
                String fullFileName = fileName + suffix;
                File file = new File(folderPath + File.separator + fullFileName);
                try {
                    if (file.createNewFile()) {
                        System.out.println("创建文件: " + file.getAbsolutePath());
                    } else {
                        System.out.println("文件已存在: " + file.getAbsolutePath());
                    }
                } catch (IOException e) {
                    System.out.println("创建文件时发生错误: " + e.getMessage());
                }
            }

            // 在basePath下创建api文件夹
            String apiFolderPath = basePath + File.separator + "api";
            File apiFolder = new File(apiFolderPath);
            if (!apiFolder.exists()) {
                if (apiFolder.mkdir()) {
                    System.out.println("创建api文件夹: " + apiFolderPath);
                } else {
                    System.out.println("创建api文件夹失败: " + apiFolderPath);
                }
            }

            // 在api文件夹内创建.ts文件
            String tsFileName = fileName + ".ts";
            File tsFile = new File(apiFolderPath + File.separator + tsFileName);
            try {
                if (tsFile.createNewFile()) {
                    System.out.println("创建文件: " + tsFile.getAbsolutePath());
                } else {
                    System.out.println("文件已存在: " + tsFile.getAbsolutePath());
                }
            } catch (IOException e) {
                System.out.println("创建文件时发生错误: " + e.getMessage());
            }
        }
    }
    public static void main(String[] args) {
        // 请修改为实际的路径
        String basePath = "E:\\test";
        // 请修改为实际的文件名集合
        String[] fileNames = {"attachInfo", "approve", "articleInfo", "noticeInfo", "amountInfo", "cashBack", "rightInfo", "couponInfo", "productInfo", "inventoryInfo", "serviceInfo   ", "orderInfo"};
        createFilesInFolders(basePath, fileNames);
    }
}